const app = getApp()
Page({
    data: {
		resourceDomain: app.resourceDomain,
    },
    onLoad: function (options) {
//         console.log(options.express_number);
//         console.log(options.company_code);
//         console.log(options.site);
        var that = this
		this.setData({
			icon:options.icon
		});
        app.request(app.apiDomain + 'index.php?c=mall&a=express', {
            express_number: options.express_number,
            company_code: options.company_code
        }, res => {
            console.log(res)
            if (res.data.status == 1) {
                // 判断返回信息是否为空
                if (res.data.data.Traces.length==0) {
                    // 物流信息不存在
                    that.setData({
                        info: 0,
                    })
                } else {
                    var list = res.data.data.Traces.reverse()
                    // 判断状态名
                    var stateName = ''
                    if (res.data.data.State == 2) {
                        stateName = '运输中...'
                        // 截取日期
                        list.forEach(item => {
                            item.datas = item.AcceptTime.substring(5, 10)
                            item.times = item.AcceptTime.substring(11, 16)
                        })
                    } else if (res.data.data.State == 3) {
                        stateName = '已签收'
                        // 取第一个  截取第一个
                        var firstLi = list[0]
                        firstLi.datas = firstLi.AcceptTime.substring(5, 10)
                        firstLi.datas = firstLi.AcceptTime.substring(11, 16)
                        list.shift()
                        console.log(list);
                        list.forEach(item => {
                            item.datas = item.AcceptTime.substring(5, 10)
                            item.times = item.AcceptTime.substring(11, 16)
                        })
                    } else if (res.data.data.State == 3) {
                        stateName = '问题件'
                    }
                    that.setData({
                        info: 1,
                        site: options.site,
                        stateName: stateName,
                        state: res.data.data.State,
                        list: list,
                        firstLi: firstLi
                    })
                }
            }
        })
    }
})
